package com.ruoyi.know.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.know.domain.Notes;
import com.ruoyi.know.mapper.NotesMapper;
import com.ruoyi.know.service.INotesService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 笔记Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-09
 */
@Service
public class NotesServiceImpl implements INotesService
{
    @Autowired
    private NotesMapper notesMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询笔记
     *
     * @param noteId 笔记主键
     * @return 笔记
     */
    @Override
    public Notes selectNotesByNoteId(Long noteId)
    {
        return notesMapper.selectNotesByNoteId(noteId);
    }

    /**
     * 查询笔记列表
     *
     * @param notes 笔记
     * @return 笔记
     */
    @Override
    public List<Notes> selectNotesList(Notes notes)
    {
        List<Notes> notesList = notesMapper.selectNotesList(notes);
        for (Notes notes1 : notesList){
            Long userId = notes1.getUserId();
            SysUser sysUser = sysUserMapper.selectUserById(userId);
            notes1.setSysUser(sysUser);
        }
        return notesList;
    }

    /**
     * 新增笔记
     *
     * @param notes 笔记
     * @return 结果
     */
    @Override
    public int insertNotes(Notes notes)
    {
        return notesMapper.insertNotes(notes);
    }

    /**
     * 修改笔记
     *
     * @param notes 笔记
     * @return 结果
     */
    @Override
    public int updateNotes(Notes notes)
    {
        return notesMapper.updateNotes(notes);
    }

    /**
     * 设置附件为空
     * @param noteId 将对应笔记的附件字段设置为空
     * @return 1 已清空 0 未清空
     */
    public int setNullForAttachUrl(Long noteId)
    {
        return notesMapper.setNullForAttachUrl(noteId);
    }

    /**
     * 批量删除笔记
     *
     * @param noteIds 需要删除的笔记主键
     * @return 结果
     */
    @Override
    public int deleteNotesByNoteIds(Long[] noteIds)
    {
        return notesMapper.deleteNotesByNoteIds(noteIds);
    }

    /**
     * 删除笔记信息
     *
     * @param noteId 笔记主键
     * @return 结果
     */
    @Override
    public int deleteNotesByNoteId(Long noteId)
    {
        return notesMapper.deleteNotesByNoteId(noteId);
    }
}
